// hyb_yl/mysubpages/pages/allevalation/allevalation.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow: true,
    imgList: ["https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp",
      "https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp",
      "https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp"
    ],
    sid:"",
    appraise:[],
    maxLength: 70,
  },
  click: function (e) {
    console.log(e)
    var index = e.currentTarget.dataset.index;
    var appraise = this.data.appraise;
    console.log(appraise)
    var text = appraise[index].pl_text.text;
    var maxLength = this.data.maxLength;
    appraise[index].pl_text.isshow = !appraise[index].pl_text.isshow
    text = (text.length > maxLength && appraise[index].pl_text.isshow) ? text.substring(0,maxLength-3) + "..." : text
    appraise[index].pl_text.textshow = text
    this.setData({
      appraise:appraise
    })
  },
  evaldetail: function (e) {
    wx.navigateTo({
      url: '/hyb_yl/onesubpages/pages/evaldetail/evaldetail',
    })
  },
  imgbtn:function(e){
    console.log(e)
    var appraise = this.data.appraise
    var index = e.currentTarget.dataset.index
    var img = e.currentTarget.dataset.item
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: appraise[index].pl_text.pic // 需要预览的图片http链接列表
    })
  },
  switchImg: function (e) {
    var img = e.currentTarget.dataset.src;
    var imglist = this.data.imgList;
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: this.data.imgList // 需要预览的图片http链接列表
    })
  },
  evaldetail:function(e){
    var that = this
    console.log(e)
    var pl_id = e.currentTarget.dataset.pl_id
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/commevaldetail/commevaldetail?pl_id=' + pl_id,
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      sid:options.sid
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getAllpinglun()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getAllpinglun: function () {
    var that = this
    var sid = that.data.sid
    app.util.request({
      'url': 'entry/wxapp/goods.pinglun',
      data: {
        sid: sid
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          appraise: res.data
        })
        var appraise = that.data.appraise;
        var maxLength = that.data.maxLength
        for(var i=0;i<appraise.length;i++){
          if(appraise[i].pl_text.text.length > maxLength){
            var textshow = appraise[i].pl_text.text.substring(0, maxLength - 3) + "..."
          }else{
            var textshow = appraise[i].pl_text.text
          }
          
          console.log(textshow)
          appraise[i].pl_text.textshow = textshow
          appraise[i].pl_text.isshow=true
        }
        that.setData({
          appraise:appraise
        })
      }
    })
  }
})